//
//  SISSPassengerInfoView.m
//  SISSAPP
//
//  Created by 优房网 on 2017/7/27.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSPassengerInfoView.h"
#import "SISSHouseTakeLookDetailModel.h"

@interface SISSPassengerInfoView ()

@property (weak, nonatomic)  UILabel *nameLabel;
@property (weak, nonatomic)  UILabel *regionAndCommunityLabel;
@property (weak, nonatomic)  UIView *horizontalLineOne;
@property (weak, nonatomic)  UIView *horizontalLineTwo;
@property (weak, nonatomic)  UIView *verticalLineOne;
@property (weak, nonatomic)  UIView *verticalLineTwo;
@property (weak, nonatomic)  UILabel *budgetLabel;
@property (weak, nonatomic)  UILabel *houseTypeLabel;
@property (weak, nonatomic)  UILabel *areaLabel;
@property (weak, nonatomic)  UILabel *intentionFloorLabel;
@property (weak, nonatomic)  UILabel *decorationLabel;
@property (weak, nonatomic)  UILabel *directionLabel;
@property (weak, nonatomic)  UILabel *purchasePurposeLabel;
@property (weak, nonatomic)  UILabel *otherDescriptionLabel;
@property (weak, nonatomic)  UILabel *insertTimeLabel;

@property (weak, nonatomic)  UILabel *budgetTitleLabel;
@property (weak, nonatomic)  UILabel *houseTypeTitleLabel;
@property (weak, nonatomic)  UILabel *areaTitleLabel;
@property (weak, nonatomic)  UILabel *intentionFloorTitleLabel;
@property (weak, nonatomic)  UILabel *decorationTitleLabel;
@property (weak, nonatomic)  UILabel *directionTitleLabel;
@property (weak, nonatomic)  UILabel *purchasePurposeTitleLabel;
@property (weak, nonatomic)  UILabel *otherDescriptionTitleLabel;
@property (weak, nonatomic)  UILabel *insertTimeTitleLabel;

@end
@implementation SISSPassengerInfoView


- (void)setTakeLookDetailModel:(SISSHouseTakeLookDetailModel *)takeLookDetailModel {
    _takeLookDetailModel = takeLookDetailModel;
    
    if (takeLookDetailModel.type == 1) {
        // 根据身份证判断显示 先生、女士
        NSString *fisrtName = [takeLookDetailModel.name substringToIndex:1];
        NSInteger idNum = [[takeLookDetailModel.idNumber substringWithRange:NSMakeRange(takeLookDetailModel.idNumber.length - 2, 1)] integerValue];
        
        NSString *genderStr = (idNum % 2) == 0 ? @"女士" : @"先生";
        self.nameLabel.text = [NSString stringWithFormat:@"%@%@  %@",fisrtName,genderStr,@"求购"];
    } else {
        self.nameLabel.text = [NSString stringWithFormat:@"%@ %@",takeLookDetailModel.name,@"求购"];
    }
    
    
    self.regionAndCommunityLabel.text = [NSString stringWithFormat:@"%@-%@ %@",takeLookDetailModel.region,takeLookDetailModel.regionDetail,takeLookDetailModel.neighbourhood.length > 0 ? takeLookDetailModel.neighbourhood : @""];
    self.budgetLabel.text = [NSString stringWithFormat:@"%@-%@万",@(takeLookDetailModel.minPrice),@(takeLookDetailModel.maxPrice)];
    self.houseTypeLabel.text = takeLookDetailModel.houseType;
    self.areaLabel.text = [NSString stringWithFormat:@"%@-%@㎡",@(takeLookDetailModel.minArea),@(takeLookDetailModel.maxArea)];
    self.intentionFloorLabel.text = (takeLookDetailModel.minFloor != 0 && takeLookDetailModel.maxFloor != 0) ? [NSString stringWithFormat:@"%zd-%zd层",takeLookDetailModel.minFloor,takeLookDetailModel.maxFloor] : @"暂无数据";
    self.decorationLabel.text = takeLookDetailModel.decoration.length ? takeLookDetailModel.decoration : @"暂无数据";
    self.directionLabel.text = takeLookDetailModel.direction.length ? takeLookDetailModel.direction : @"暂无数据";
    self.purchasePurposeLabel.text = takeLookDetailModel.purpose.length ? takeLookDetailModel.purpose : @"暂无数据";
    self.otherDescriptionLabel.text = takeLookDetailModel.otherdesc.length ? takeLookDetailModel.otherdesc : @"暂无数据";
    
    self.insertTimeTitleLabel.text = @"看房时间";
    self.insertTimeLabel.text = [takeLookDetailModel.takeLookDate substringToIndex:10];
}

#pragma mark - UI
- (void)initUI {
    [super initUI];
    
    self.backgroundColor = [UIColor whiteColor];
    
    UILabel *nameLabel = [UILabel yyr_labelWithText:@"--" fontSize:20 textColor:MAIN_TEXT_COLOR];
    nameLabel.font = [UIFont boldSystemFontOfSize:20];
    [self addSubview:nameLabel];
    self.nameLabel = nameLabel;
    
    UILabel *regionAndCommunityLabel = [UILabel yyr_labelWithText:@"--" fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:regionAndCommunityLabel];
    self.regionAndCommunityLabel = regionAndCommunityLabel;
    
    UIView *horizontalLineOne = [[UIView alloc] init];
    horizontalLineOne.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self addSubview:horizontalLineOne];
    self.horizontalLineOne = horizontalLineOne;
    
    UIView *horizontalLineTwo = [[UIView alloc] init];
    horizontalLineTwo.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self addSubview:horizontalLineTwo];
    self.horizontalLineTwo = horizontalLineTwo;
    
    UIView *verticalLineOne = [[UIView alloc] init];
    verticalLineOne.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self addSubview:verticalLineOne];
    self.verticalLineOne = verticalLineOne;
    
    UIView *verticalLineTwo = [[UIView alloc] init];
    verticalLineTwo.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self addSubview:verticalLineTwo];
    self.verticalLineTwo = verticalLineTwo;
    
    UILabel *budgetTitleLabel = [UILabel yyr_labelWithText:@"预算" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:budgetTitleLabel];
    self.budgetTitleLabel = budgetTitleLabel;
    
    UILabel *budgetLabel = [UILabel yyr_labelWithText:@"--" fontSize:17 textColor:COLOR(0xFF6286)];
    [self addSubview:budgetLabel];
    self.budgetLabel = budgetLabel;
    
    UILabel *houseTypeTitleLabel = [UILabel yyr_labelWithText:@"户型" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:houseTypeTitleLabel];
    self.houseTypeTitleLabel = houseTypeTitleLabel;
    
    UILabel *houseTypeLabel = [UILabel yyr_labelWithText:@"--" fontSize:17 textColor:COLOR(0xFF6286)];
    [self addSubview:houseTypeLabel];
    self.houseTypeLabel = houseTypeLabel;
    
    UILabel *areaTitleLabel = [UILabel yyr_labelWithText:@"面积" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:areaTitleLabel];
    self.areaTitleLabel = areaTitleLabel;
    
    UILabel *areaLabel = [UILabel yyr_labelWithText:@"--" fontSize:17 textColor:COLOR(0xFF6286)];
    [self addSubview:areaLabel];
    self.areaLabel = areaLabel;
    
    UILabel *intentionFloorTitleLabel = [UILabel yyr_labelWithText:@"意向楼层：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:intentionFloorTitleLabel];
    self.intentionFloorTitleLabel = intentionFloorTitleLabel;
    
    UILabel *intentionFloorLabel = [UILabel yyr_labelWithText:@"--" fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:intentionFloorLabel];
    self.intentionFloorLabel = intentionFloorLabel;
    
    UILabel *decorationTitleLabel = [UILabel yyr_labelWithText:@"装修程度：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:decorationTitleLabel];
    self.decorationTitleLabel = decorationTitleLabel;
    
    UILabel *decorationLabel = [UILabel yyr_labelWithText:@"--" fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:decorationLabel];
    self.decorationLabel = decorationLabel;
    
    UILabel *directionTitleLabel = [UILabel yyr_labelWithText:@"朝向：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:directionTitleLabel];
    self.directionTitleLabel = directionTitleLabel;
    
    UILabel *directionLabel = [UILabel yyr_labelWithText:@"--" fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:directionLabel];
    self.directionLabel = directionLabel;
    
    UILabel *purchasePurposeTitleLabel = [UILabel yyr_labelWithText:@"购房目的：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:purchasePurposeTitleLabel];
    self.purchasePurposeTitleLabel = purchasePurposeTitleLabel;
    
    UILabel *purchasePurposeLabel = [UILabel yyr_labelWithText:@"--" fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:purchasePurposeLabel];
    self.purchasePurposeLabel = purchasePurposeLabel;
    
    UILabel *otherDescriptionTitleLabel = [UILabel yyr_labelWithText:@"其他需求说明：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:otherDescriptionTitleLabel];
    self.otherDescriptionTitleLabel = otherDescriptionTitleLabel;
    
    UILabel *otherDescriptionLabel = [UILabel yyr_labelWithText:@"--" fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:otherDescriptionLabel];
    self.otherDescriptionLabel = otherDescriptionLabel;
    
    UILabel *insertTimeTitleLabel = [UILabel yyr_labelWithText:@"发布时间：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:insertTimeTitleLabel];
    self.insertTimeTitleLabel = insertTimeTitleLabel;
    
    UILabel *insertTimeLabel = [UILabel yyr_labelWithText:@"--" fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:insertTimeLabel];
    self.insertTimeLabel = insertTimeLabel;
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf
    CGFloat margin = 8.0;
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(weakSelf).offset(3 * margin);
    }];
    
    [self.regionAndCommunityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.nameLabel.mas_right).offset(margin);
        make.bottom.equalTo(weakSelf.nameLabel);
    }];
    
    [self.horizontalLineOne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.nameLabel);
        make.top.equalTo(weakSelf.nameLabel.mas_bottom).offset(3 * margin);
        make.right.equalTo(weakSelf).offset(-3 * margin);
        make.height.mas_equalTo(1);
    }];
    
    [self.verticalLineOne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.horizontalLineOne.mas_bottom).offset(2 * margin);
        make.centerX.equalTo(weakSelf).multipliedBy(0.7);
        make.height.mas_equalTo(60);
        make.width.mas_equalTo(1);
    }];
    
    [self.verticalLineTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.horizontalLineOne.mas_bottom).offset(2 * margin);
        make.centerX.equalTo(weakSelf).multipliedBy(1.3);
        make.height.mas_equalTo(60);
        make.width.mas_equalTo(1);
    }];
    
    [self.horizontalLineTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.height.width.equalTo(weakSelf.horizontalLineOne);
        make.top.equalTo(weakSelf.verticalLineOne.mas_bottom).offset(2 * margin);
    }];
    
    [self.budgetTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.nameLabel);
        make.top.equalTo(weakSelf.horizontalLineOne.mas_bottom).offset(2.5 * margin);
    }];
    
    [self.budgetLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.budgetTitleLabel);
        make.top.equalTo(weakSelf.budgetTitleLabel.mas_bottom).offset(margin);
    }];
    
    [self.houseTypeTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.budgetTitleLabel);
        make.left.equalTo(weakSelf.verticalLineOne.mas_right).offset(2 * margin);
    }];
    
    [self.houseTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.houseTypeTitleLabel);
        make.centerY.equalTo(weakSelf.budgetLabel);
    }];
    
    [self.areaTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.budgetTitleLabel);
        make.left.equalTo(weakSelf.verticalLineTwo.mas_right).offset(2 * margin);
    }];
    
    [self.areaLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.areaTitleLabel);
        make.centerY.equalTo(weakSelf.budgetLabel);
    }];
    
    [self.intentionFloorTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.nameLabel);
        make.top.equalTo(weakSelf.horizontalLineTwo.mas_bottom).offset(2 * margin);
    }];
    
    [self.decorationTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.intentionFloorTitleLabel);
        make.top.equalTo(weakSelf.intentionFloorTitleLabel.mas_bottom).offset(2 * margin);
    }];
    
    [self.directionTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.decorationTitleLabel);
        make.top.equalTo(weakSelf.decorationTitleLabel.mas_bottom).offset(2 * margin);
    }];
    
    [self.purchasePurposeTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.directionTitleLabel);
        make.top.equalTo(weakSelf.directionTitleLabel.mas_bottom).offset(2 * margin);
    }];
    
    [self.otherDescriptionTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.purchasePurposeTitleLabel);
        make.top.equalTo(weakSelf.purchasePurposeTitleLabel.mas_bottom).offset(2 * margin);
    }];
    
    
    
    [self.intentionFloorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.intentionFloorTitleLabel.mas_right).offset(4 * margin);
        make.centerY.equalTo(weakSelf.intentionFloorTitleLabel);
    }];
    
    [self.decorationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.intentionFloorLabel);
        make.centerY.equalTo(weakSelf.decorationTitleLabel);
    }];
    
    [self.directionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.intentionFloorLabel);
        make.centerY.equalTo(weakSelf.directionTitleLabel);
    }];
    
    [self.purchasePurposeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.intentionFloorLabel);
        make.centerY.equalTo(weakSelf.purchasePurposeTitleLabel);
    }];
    
    [self.otherDescriptionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.otherDescriptionTitleLabel).offset(0.5 * margin);
        make.top.equalTo(weakSelf.otherDescriptionTitleLabel.mas_bottom).offset(margin);
    }];
    
    [self.insertTimeTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.otherDescriptionTitleLabel);
        make.top.equalTo(weakSelf.otherDescriptionLabel.mas_bottom).offset(2 * margin);
        make.bottom.equalTo(weakSelf).offset(-margin);
    }];
    
    [self.insertTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.intentionFloorLabel);
        make.centerY.equalTo(weakSelf.insertTimeTitleLabel);
    }];
}

@end
